/*
	porvice interfact for C languege
	Jun creat on 16/7/21
*/

#ifndef INCLUDE_PlaneNavigation
#define INCLUDE_PlaneNavigation

/* multi-threading cross platform implement
* cp means cross-platform */
#ifdef WIN32
#include <windows.h>
#include <process.h>
typedef HANDLE CP_MUTEXLOCK; // the mutex lock variable type
#define CreatMutexCP(mlock) \
do { \
    CP_MUTEXLOCK *tmp_lock = CreateMutex(NULL, FALSE, NULL); \
    *tmp_lock = ;\
    mlock = tmp_lock; \
} while(0)

#define WaitMutexCP(hMutex) WaitForSingleObject(hMutex, INFINITE)
#define ExitMutexCP(hMutex) ReleaseMutex(hMutex)
#define DelayCP(msecond) Sleep(msecond)
#define CreatThreadCP(ThreadFun) _beginthreadex(NULL, 0, ThreadFun, NULL, 0, NULL);
#else /* !WIN32 */
// LINUX OR OTHER SYSTEM
#define __stdcall
#include <pthread.h>
#include <unistd.h>

typedef pthread_mutex_t CP_MUTEXLOCK; // the mutex lock variable type

									  /* Linux */
#define CreatMutexCP(mlock) \
do { \
	pthread_mutex_init(mlock, NULL); \
} while(0)



#define WaitMutexCP(hMutex) pthread_mutex_lock(&hMutex)
#define ExitMutexCP(hMutex) pthread_mutex_unlock(&hMutex)
#define DelayCP(msecond) usleep(msecond * 1000)
									  // #define CreatThreadCP(ThreadFun) pthread_create()
#endif /* WIN32 */

#define MAX_MARK 15
struct MarkInfo
{
	int id; // the mark id. range:0 ~ 1023
	float x; // the camera position x
	float y; // the camera position y
	float z; // the camera position z
	float spin_x; // the camera x-axis spin angle
	float spin_y; // the camera y-axis spin angle
	float spin_z; // the camera z-axis spin angle
};
struct _pt
{
	int x;
	int y;
};
typedef struct _CamPos
{
	int isDetected; // Is detected the mark? 0 for false, 1 for true
	int quantity; // how many mark is detected
	int height; // the deteceted height by US100
	struct MarkInfo markInfo[MAX_MARK];
	int err_no; // record error information, no error is 0 
	int stopRem; // when this value set to 1, the detect function will stop the cycle
	struct _pt initPt; // init point
	float initArea; // init logo area
	int isInitDet; // Is init mark detected?
	int flymode;// flymode 0 for forward, 1 for stay
	float initAngle;
}CamPos;
#ifndef __cplusplus
void updatePosition(CamPos * camPos, CP_MUTEXLOCK * mlock);
#endif // !__Cplusplus


#endif // !INCLUDE_PlaneNavigation

